home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-3.98 / gdb / gdb.info-3 < prev    next >
Encoding:
Text File  |  1991-08-01  |  45.5 KB  |  1,255 lines

  1. Info file gdb.info, produced by Makeinfo, -*- Text -*- from input
  2. file gdb-all.texinfo.
  3.  
  4.    This file documents the GNU debugger GDB.
  5.  
  6.    Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of
  9. this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.  
  13.    Permission is granted to copy and distribute modified versions of
  14. this
  15. manual under the conditions for verbatim copying, provided also that
  16. the section entitled "GNU General Public License" is included
  17. exactly as in the original, and provided that the entire resulting
  18. derived work is distributed under the terms of a permission notice
  19. identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for
  23. modified versions, except that the section entitled "GNU General
  24. Public License" may be included in a translation approved by the
  25. Free Software Foundation instead of in the original English.
  26.  
  27. 
  28. File: gdb.info,  Node: Machine Code,  Prev: Source Path,  Up: Source
  29.  
  30. Source and Machine Code
  31. =======================
  32.  
  33.    You can use the command `info line' to map source lines to program
  34. addresses
  35. (and viceversa), and the command `disassemble' to display a range of
  36. addresses as machine instructions.
  37.  
  38. `info line LINESPEC'
  39.      Print the starting and ending addresses of the compiled code for
  40.      source line LINESPEC.  You can specify source lines in any of
  41.      the ways understood by the `list' command (*note List::.).
  42.  
  43.    For example, we can use `info line' to inquire on where the object
  44. code for the first line of function `m4_changequote' lies:
  45.  
  46.      (gdb) info line m4_changecom
  47.      Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
  48.  
  49. We can also inquire (using `*ADDR' as the form for LINESPEC) what
  50. source line covers a particular address:
  51.  
  52.      (gdb) info line *0x63ff
  53.      Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
  54.  
  55.    After `info line', the default address for the `x' command is
  56. changed to the starting address of the line, so that `x/i' is
  57. sufficient to begin examining the machine code (*note Memory::.). 
  58. Also, this address is saved as the value of the convenience variable
  59. `$_' (*note Convenience Vars::.).
  60.  
  61. `disassemble'
  62.      This specialized command is provided to dump a range of memory
  63.      as machine instructions.  The default memory range is the
  64.      function surrounding the program counter of the selected frame.
  65.      A single argument to this command is a program counter value;
  66.      the function surrounding this value will be dumped.  Two
  67.      arguments (separated by one or more spaces) specify a range of
  68.      addresses (first inclusive, second exclusive) to be dumped.
  69.  
  70.    We can use `disassemble' to inspect the object code range shown in
  71. the last `info line' example:
  72.  
  73.      (gdb) disas 0x63e4 0x6404
  74.      Dump of assembler code from 0x63e4 to 0x6404:
  75.      0x63e4 builtin_init+5340:    ble 0x63f8 builtin_init+5360
  76.      0x63e8 builtin_init+5344:    sethi %hi(0x4c00), %o0
  77.      0x63ec builtin_init+5348:    ld [%i1+4], %o0
  78.      0x63f0 builtin_init+5352:    b 0x63fc builtin_init+5364
  79.      0x63f4 builtin_init+5356:    ld [%o0+4], %o0
  80.      0x63f8 builtin_init+5360:    or %o0, 0x1a4, %o0
  81.      0x63fc builtin_init+5364:    call 0x9288 path_search
  82.      0x6400 builtin_init+5368:    nop 
  83.      End of assembler dump.
  84.      (gdb)
  85.  
  86. 
  87. File: gdb.info,  Node: Data,  Next: Symbols,  Prev: Source,  Up: Top
  88.  
  89. Examining Data
  90. **************
  91.  
  92.    The usual way to examine data in your program is with the `print'
  93. command
  94. (abbreviated `p'), or its synonym `inspect'.  It evaluates and
  95. prints the value of any valid expression of the language the program
  96. is written in (for now, C or C++).  You type
  97.  
  98.      print EXP
  99.  
  100. where EXP is any valid expression (in the source language), and the
  101. value of EXP is printed in a format appropriate to its data type.
  102.  
  103.    A more low-level way of examining data is with the `x' command. 
  104. It examines data in memory at a specified address and prints it in a
  105. specified format.  *Note Memory::.
  106.  
  107. * Menu:
  108.  
  109. * Expressions::            Expressions
  110. * Variables::            Program Variables
  111. * Arrays::            Artificial Arrays
  112. * Output formats::        Output formats
  113. * Memory::            Examining Memory
  114. * Auto Display::        Automatic Display
  115. * Print Settings::        Print Settings
  116. * Value History::        Value History
  117. * Convenience Vars::        Convenience Variables
  118. * Registers::            Registers
  119. * Floating Point Hardware::    Floating Point Hardware
  120.  
  121. 
  122. File: gdb.info,  Node: Expressions,  Next: Variables,  Prev: Data,  Up: Data
  123.  
  124. Expressions
  125. ===========
  126.  
  127.    `print' and many other GDB commands accept an expression and
  128. compute its value.  Any kind of constant, variable or operator
  129. defined by the programming language you are using is legal in an
  130. expression in GDB.  This includes conditional expressions, function
  131. calls, casts and string constants.  It unfortunately does not
  132. include symbols defined by preprocessor `#define' commands,
  133. or C++ expressions involving `::', the name resolution operator.
  134.  
  135.    Casts are supported in all languages, not just in C, because it is
  136. so useful to cast a number into a pointer so as to examine a
  137. structure at that address in memory.
  138.  
  139.    GDB supports three kinds of operator in addition to those of
  140. programming languages:
  141.  
  142. `@'
  143.      `@' is a binary operator for treating parts of memory as arrays.
  144.      *Note Arrays::, for more information.
  145.  
  146. `::'
  147.      `::' allows you to specify a variable in terms of the file or
  148.      function where it is defined.  *Note Variables::.
  149.  
  150. `{TYPE} ADDR'
  151.      Refers to an object of type TYPE stored at address ADDR in
  152.      memory.  ADDR may be any expression whose value is an integer
  153.      or pointer (but parentheses are required around binary
  154.      operators, just as in a cast).  This construct is allowed
  155.      regardless of what kind of data is normally supposed to reside
  156.      at ADDR.
  157.  
  158. 
  159. File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Expressions,  Up: Data
  160.  
  161. Program Variables
  162. =================
  163.  
  164.    The most common kind of expression to use is the name of a
  165. variable in your program.
  166.  
  167.    Variables in expressions are understood in the selected stack
  168. frame (*note Selection::.); they must either be global (or static)
  169. or be visible according to the scope rules of the programming
  170. language from the point of execution in that frame.  This means that
  171. in the function
  172.  
  173.      foo (a)
  174.           int a;
  175.      {
  176.        bar (a);
  177.        {
  178.          int b = test ();
  179.          bar (b);
  180.        }
  181.      }
  182.  
  183. the variable `a' is usable whenever the program is executing within
  184. the function `foo', but the variable `b' is visible only while the
  185. program is executing inside the block in which `b' is declared.
  186.  
  187.    There is an exception: you can refer to a variable or function
  188. whose scope is a single source file even if the current execution
  189. point is not in this file.  But it is possible to have more than one
  190. such variable or function with the same name (in different source
  191. files).  If that happens, referring to that name has unpredictable
  192. effects.  If you wish, you can specify a variable in a particular
  193. file, using the colon-colon notation:
  194.  
  195.      FILE::VARIABLE
  196.  
  197. Here FILE is the name of the source file whose variable you want.
  198.  
  199.    This use of `::' is very rarely in conflict with the very similar
  200. use of the same notation in C++.  GDB also supports use of the C++
  201. name resolution operator in GDB expressions.
  202.  
  203.      *Warning:* Occasionally, a local variable may appear to have the
  204.      wrong value at certain points in a function--just after entry
  205.      to the function, and just before exit.  You may see this
  206.      problem when you're stepping by machine instructions.  This is
  207.      because on most machines, it takes more than one instruction to
  208.      set up a stack frame (including local variable definitions); if
  209.      you're stepping by machine instructions, variables may appear
  210.      to have the wrong values until the stack frame is completely
  211.      built.  On function exit, it usually also takes more than one
  212.      machine instruction to destroy a stack frame; after you begin
  213.      stepping through that group of instructions, local variable
  214.      definitions may be gone.
  215.  
  216. 
  217. File: gdb.info,  Node: Arrays,  Next: Output formats,  Prev: Variables,  Up: Data
  218.  
  219. Artificial Arrays
  220. =================
  221.  
  222.    It is often useful to print out several successive objects of the
  223. same type in memory; a section of an array, or an array of
  224. dynamically determined size for which only a pointer exists in the
  225. program.
  226.  
  227.    This can be done by constructing an "artificial array" with the
  228. binary operator `@'.  The left operand of `@' should be the first
  229. element of the desired array, as an individual object.  The right
  230. operand
  231. should be the desired length of the array.  The result is an array
  232. value whose elements are all of the type of the left argument.  The
  233. first element is actually the left argument; the second element
  234. comes from bytes of memory immediately following those that hold the
  235. first element, and so on.  Here is an example.  If a program says
  236.  
  237.      int *array = (int *) malloc (len * sizeof (int));
  238.  
  239. you can print the contents of `array' with
  240.  
  241.      p *array@len
  242.  
  243.    The left operand of `@' must reside in memory.  Array values made
  244. with `@' in this way behave just like other arrays in terms of
  245. subscripting, and are coerced to pointers when used in expressions. 
  246. Artificial arrays most often appear in expressions via the value
  247. history (*note Value History::.), after printing one out.)
  248.  
  249.    Sometimes the artificial array mechanism isn't quite enough; in
  250. moderately complex data structures, the elements of interest may not
  251. actually be adjacent--for example, if you're interested in the
  252. values of pointers in an array.  One useful work-around in this
  253. situation is to use a convenience variable (*note Convenience
  254. Vars::.) as a counter in an expression that prints the first
  255. interesting value, and then repeat that expression via RET.  For
  256. instance, suppose you have an array `dtab' of pointers to
  257. structures, and you're interested in the values of a field `fv' in
  258. each structure.  Here's an example of what you might type:
  259.  
  260.      set $i = 0
  261.      p dtab[$i++]->fv
  262.      RET
  263.      RET
  264.      ...
  265.  
  266. 
  267. File: gdb.info,  Node: Output formats,  Next: Memory,  Prev: Arrays,  Up: Data
  268.  
  269. Output formats
  270. ==============
  271.  
  272.    By default, GDB prints a value according to its data type. 
  273. Sometimes this is not what you want.  For example, you might want to
  274. print a number in hex, or a pointer in decimal.  Or you might want
  275. to view data in memory at a certain address as a character string or
  276. as an instruction.  To do these things, specify an "output format"
  277. when you print a value.
  278.  
  279.    The simplest use of output formats is to say how to print a value
  280. already computed.  This is done by starting the arguments of the
  281. `print' command with a slash and a format letter.  The format
  282. letters supported are:
  283.  
  284. `x'
  285.      Regard the bits of the value as an integer, and print the
  286.      integer in hexadecimal.
  287.  
  288. `d'
  289.      Print as integer in signed decimal.
  290.  
  291. `u'
  292.      Print as integer in unsigned decimal.
  293.  
  294. `o'
  295.      Print as integer in octal.
  296.  
  297. `t'
  298.      Print as integer in binary.  The letter `t' stands for "two".
  299.  
  300. `a'
  301.      Print as an address, both absolute in hex and as an offset from
  302.      the nearest preceding symbol.  This format can be used to
  303.      discover where (in what function) an unknown address is located:
  304.  
  305.           (gdb) p/a 0x54320
  306.           $3 = 0x54320 <_initialize_vx+396>
  307.  
  308. `c'
  309.      Regard as an integer and print it as a character constant.
  310.  
  311. `f'
  312.      Regard the bits of the value as a floating point number and
  313.      print
  314.      using typical floating point syntax.
  315.  
  316.    For example, to print the program counter in hex (*note
  317. Registers::.), type
  318.  
  319.      p/x $pc
  320.  
  321. Note that no space is required before the slash; this is because
  322. command names in GDB cannot contain a slash.
  323.  
  324.    To reprint the last value in the value history with a different
  325. format, you can use the `print' command with just a format and no
  326. expression.  For example, `p/x' reprints the last value in hex.
  327.  
  328. 
  329. File: gdb.info,  Node: Memory,  Next: Auto Display,  Prev: Output formats,  Up: Data
  330.  
  331. Examining Memory
  332. ================
  333.  
  334. `x/NFU EXPR'
  335.      The command `x' (for `examine') can be used to examine memory
  336.      without being constrained by your program's data types.  You
  337.      can specify the unit size U of memory to inspect, and a repeat
  338.      count N of how many of those units to display.  `x' understands
  339.      the formats F used by `print'; two additional formats, `s'
  340.      (string) and `i' (machine instruction) can be used without
  341.      specifying a unit size.
  342.  
  343.    For example, `x/3uh 0x54320' is a request to display three
  344. halfwords (`h') of memory, formatted as unsigned decimal integers
  345. (`u'),
  346. starting at address `0x54320'.  `x/4xw $sp' prints the four words
  347. (`w') of memory above the stack pointer (here, `$sp'; *note
  348. Registers::.) in hexadecimal (`x').
  349.  
  350.    Since the letters indicating unit sizes are all distinct from the
  351. letters specifying output formats, you don't have to remember
  352. whether unit size or format comes first; either order will work. 
  353. The output specifications `4xw' and `4wx' mean exactly the same thing.
  354.  
  355.    After the format specification, you supply an expression for the
  356. address where GDB is to begin reading from memory.  The expression
  357. need not have a pointer value (though it may); it is always
  358. interpreted as an integer address of a byte of memory.  *Note
  359. Expressions:: for more information on expressions.
  360.  
  361.    These are the memory units U you can specify with the `x' command:
  362.  
  363. `b'
  364.      Examine individual bytes.
  365.  
  366. `h'
  367.      Examine halfwords (two bytes each).
  368.  
  369. `w'
  370.      Examine words (four bytes each).
  371.  
  372.      Many assemblers and cpu designers still use `word' for a 16-bit
  373.      quantity, as a holdover from specific predecessor machines of
  374.      the 1970's that really did use two-byte words.  But more
  375.      generally the term `word' has always referred to the size of
  376.      quantity that a machine normally operates on and stores in its
  377.      registers.  This is 32 bits for all the machines that GDB runs
  378.      on.
  379.  
  380. `g'
  381.      Examine giant words (8 bytes).
  382.  
  383.    You can combine these unit specifications with any of the formats
  384. described for `print'.  *Note Output formats::.
  385.  
  386.    `x' has two additional output specifications which derive the unit
  387. size from the data inspected:
  388.  
  389. `s'
  390.      Print a null-terminated string of characters.  Any explicitly
  391.      specified unit size is ignored; instead, the unit is however
  392.      many bytes it takes to reach a null character (including the
  393.      null character).
  394.  
  395. `i'
  396.      Print a machine instruction in assembler syntax (or nearly). 
  397.      Any specified unit size is ignored; the number of bytes in an
  398.      instruction varies depending on the type of machine, the opcode
  399.      and the addressing modes used.  The command `disassemble' gives
  400.      an alternative way of inspecting machine instructions.  *Note
  401.      Machine Code::.
  402.  
  403.    If you omit either the format F or the unit size U, `x' will use
  404. the same one that was used last.  If you don't use any letters or
  405. digits after the slash, you can omit the slash as well.
  406.  
  407.    You can also omit the address to examine.  Then the address used
  408. is just after the last unit examined.  This is why string and
  409. instruction formats actually compute a unit-size based on the data:
  410. so that the next string or instruction examined will start in the
  411. right place.
  412.  
  413.    When the `print' command shows a value that resides in memory,
  414. `print' also sets the default address for the `x' command.  `info
  415. line' also sets the default for `x', to the address of the start of
  416. the machine code for the specified line (*note Machine Code::.), and
  417. `info breakpoints' sets it to the address of the last breakpoint
  418. listed (*note Set Breaks::.).
  419.  
  420.    When you use RET to repeat an `x' command, the address specified
  421. previously (if any) is ignored, so that the repeated command
  422. examines the successive locations in memory rather than the same ones.
  423.  
  424.    You can examine several consecutive units of memory with one
  425. command by writing a repeat-count after the slash (before the format
  426. letters, if any).  Omitting the repeat count N displays one unit of
  427. the appropriate size.  The repeat count must be a decimal integer. 
  428. It has the same effect as repeating the `x' command N times except
  429. that the output may be more compact, with several units per line. 
  430. For example,
  431.  
  432.      x/10i $pc
  433.  
  434. prints ten instructions starting with the one to be executed next in
  435. the selected frame.  After doing this, you could print a further
  436. seven instructions with
  437.  
  438.      x/7
  439.  
  440. --where the format and address are allowed to default.
  441.  
  442.    The addresses and contents printed by the `x' command are not put
  443. in the value history because there is often too much of them and
  444. they would get in the way.  Instead, GDB makes these values
  445. available for subsequent use in expressions as values of the
  446. convenience variables `$_' and `$__'.  After an `x' command, the
  447. last address examined is available for use in expressions in the
  448. convenience variable `$_'.  The contents of that address, as
  449. examined, are available in the convenience variable `$__'.
  450.  
  451.    If the `x' command has a repeat count, the address and contents
  452. saved are from the last memory unit printed; this is not the same as
  453. the last address printed if several units were printed on the last
  454. line of output.
  455.  
  456. 
  457. File: gdb.info,  Node: Auto Display,  Next: Print Settings,  Prev: Memory,  Up: Data
  458.  
  459. Automatic Display
  460. =================
  461.  
  462.    If you find that you want to print the value of an expression
  463. frequently (to see how it changes), you might want to add it to the
  464. "automatic
  465. display list" so that GDB will print its value each time the program
  466. stops.  Each expression added to the list is given a number to
  467. identify it; to remove an expression from the list, you specify that
  468. number.  The automatic display looks like this:
  469.  
  470.      2: foo = 38
  471.      3: bar[5] = (struct hack *) 0x3804
  472.  
  473. showing item numbers, expressions and their current values.  As with
  474. displays you request manually using `x' or `print', you can specify
  475. the output format you prefer; in fact, `display' decides whether to
  476. use `print' or `x' depending on how elaborate your format
  477. specification
  478. is--it uses `x' if you specify a unit size, or one of the two
  479. formats (`i' and `s') that are only supported by `x'; otherwise it
  480. uses `print'.
  481.  
  482. `display EXP'
  483.      Add the expression EXP to the list of expressions to display
  484.      each time the program stops.  *Note Expressions::.
  485.  
  486.      `display' will not repeat if you press RET again after using it.
  487.  
  488. `display/FMT EXP'
  489.      For FMT specifying only a display format and not a size or
  490.      count, add the expression EXP to the auto-display list but
  491.      arranges to display it each time in the specified format FMT. 
  492.      *Note Output formats::.
  493.  
  494. `display/FMT ADDR'
  495.      For FMT `i' or `s', or including a unit-size or a number of
  496.      units, add the expression ADDR as a memory address to be
  497.      examined each time the program stops.  Examining means in
  498.      effect doing `x/FMT ADDR'.  *Note Memory::.
  499.  
  500.    For example, `display/i $pc' can be helpful, to see the machine
  501. instruction about to be executed each time execution stops (`$pc' is
  502. a common name for the program counter; *note Registers::.).
  503.  
  504. `undisplay DNUMS...'
  505. `delete display DNUMS...'
  506.      Remove item numbers DNUMS from the list of expressions to display.
  507.  
  508.      `undisplay' will not repeat if you press RET after using it. 
  509.      (Otherwise you would just get the error `No display number ...'.)
  510.  
  511. `disable display DNUMS...'
  512.      Disable the display of item numbers DNUMS.  A disabled display
  513.      item is not printed automatically, but is not forgotten.  It
  514.      may be enabled again later.
  515.  
  516. `enable display DNUMS...'
  517.      Enable display of item numbers DNUMS.  It becomes effective once
  518.      again in auto display of its expression, until you specify
  519.      otherwise.
  520.  
  521. `display'
  522.      Display the current values of the expressions on the list, just
  523.      as is done when the program stops.
  524.  
  525. `info display'
  526.      Print the list of expressions previously set up to display
  527.      automatically, each one with its item number, but without
  528.      showing the values.  This includes disabled expressions, which
  529.      are marked as such.  It also includes expressions which would
  530.      not be displayed right now because they refer to automatic
  531.      variables not currently available.
  532.  
  533.    If a display expression refers to local variables, then it does
  534. not make sense outside the lexical context for which it was set up. 
  535. Such an expression is disabled when execution enters a context where
  536. one of its variables is not defined.  For example, if you give the
  537. command `display last_char' while inside a function with an argument
  538. `last_char', then this argument will be displayed while the program
  539. continues to stop inside that function.  When it stops
  540. elsewhere--where there is no variable `last_char'--display is
  541. disabled.  The next time your program stops where `last_char' is
  542. meaningful, you can enable the display expression once again.
  543.  
  544. 
  545. File: gdb.info,  Node: Print Settings,  Next: Value History,  Prev: Auto Display,  Up: Data
  546.  
  547. Print Settings
  548. ==============
  549.  
  550.    GDB provides the following ways to control how arrays, structures,
  551. and symbols are printed.
  552.  
  553. These settings are useful for debugging programs in any language:
  554.  
  555. `set print address'
  556. `set print address on'
  557.      GDB will print memory addresses showing the location of stack
  558.      traces, structure values, pointer values, breakpoints, and so
  559.      forth, even when it also displays the contents of those
  560.      addresses.  The default is on.  For example, this is what a
  561.      stack frame display looks like, with `set print address on':
  562.  
  563.           (gdb) f
  564.           #0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>") 
  565.               at input.c:530
  566.           530        if (lquote != def_lquote)
  567.  
  568. `set print address off'
  569.      Do not print addresses when displaying their contents.  For
  570.      example, this is the same stack frame displayed with `set print
  571.      address off':
  572.  
  573.           (gdb) set print addr off
  574.           (gdb) f
  575.           #0  set_quotes (lq="<<", rq=">>") at input.c:530
  576.           530        if (lquote != def_lquote)
  577.  
  578. `show print address'
  579.      Show whether or not addresses are to be printed.
  580.  
  581. `set print array'
  582. `set print array on'
  583.      GDB will pretty print arrays.  This format is more convenient to
  584.      read, but uses more space.  The default is off.
  585.  
  586. `set print array off.'
  587.      Return to compressed format for arrays.
  588.  
  589. `show print array'
  590.      Show whether compressed or pretty format is selected for
  591.      displaying arrays.
  592.  
  593. `set print elements NUMBER-OF-ELEMENTS'
  594.      If GDB is printing a large array, it will stop printing after it
  595.      has printed the number of elements set by the `set print
  596.      elements' command.  This limit also applies to the display of
  597.      strings.
  598.  
  599. `show print elements'
  600.      Display the number of elements of a large array that GDB will
  601.      print before losing patience.
  602.  
  603. `set print pretty on'
  604.      Cause GDB to print structures in an indented format with one
  605.      member per line, like this:
  606.  
  607.           $1 = {
  608.             next = 0x0,
  609.             flags = {
  610.               sweet = 1,
  611.               sour = 1
  612.             },
  613.             meat = 0x54 "Pork"
  614.           }
  615.  
  616. `set print pretty off'
  617.      Cause GDB to print structures in a compact format, like this:
  618.  
  619.           $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, meat \
  620.           = 0x54 "Pork"}
  621.  
  622.      This is the default format.
  623.  
  624. `show print pretty'
  625.      Show which format GDB will use to print structures.
  626.  
  627. `set print sevenbit-strings on'
  628.      Print using only seven-bit characters; if this option is set, 
  629.      GDB will display any eight-bit characters (in strings or
  630.      character values) using the notation `\'NNN.  For example,
  631.      `M-a' is displayed as `\341'.
  632.  
  633. `set print sevenbit-strings off'
  634.      Print using either seven-bit or eight-bit characters, as
  635.      required.  This is the default.
  636.  
  637. `show print sevenbit-strings'
  638.      Show whether or not GDB will print only seven-bit characters.
  639.  
  640. `set print union on'
  641.      Tell GDB to print unions which are contained in structures. 
  642.      This is the default setting.
  643.  
  644. `set print union off'
  645.      Tell GDB not to print unions which are contained in structures.
  646.  
  647. `show print union'
  648.      Ask GDB whether or not it will print unions which are contained
  649.      in structures.
  650.  
  651.      For example, given the declarations
  652.  
  653.           typedef enum {Tree, Bug} Species;
  654.           typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
  655.           typedef enum {Caterpillar, Cocoon, Butterfly} Bug_forms;
  656.           
  657.           struct thing {
  658.             Species it;
  659.             union {
  660.               Tree_forms tree;
  661.               Bug_forms bug;
  662.             } form;
  663.           };
  664.           
  665.           struct thing foo = {Tree, {Acorn}};
  666.  
  667.      with `set print union on' in effect `p foo' would print
  668.  
  669.           $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
  670.  
  671.      and with `set print union off' in effect it would print
  672.  
  673.           $1 = {it = Tree, form = {...}}
  674.  
  675. These settings are of interest when debugging C++ programs:
  676.  
  677. `set print demangle'
  678. `set print demangle on'
  679.      Print C++ names in their source form rather than in the mangled
  680.      form in which they are passed to the assembler and linker for
  681.      type-safe linkage.  The default is on.
  682.  
  683. `show print demangle'
  684.      Show whether C++ names will be printed in mangled or demangled
  685.      form.
  686.  
  687. `set print asm-demangle'
  688. `set print asm-demangle on'
  689.      Print C++ names in their source form rather than their mangled
  690.      form, even in assembler code printouts such as instruction
  691.      disassemblies.  The default is off.
  692.  
  693. `show print asm-demangle'
  694.      Show whether C++ names in assembly listings will be printed in
  695.      mangled or demangled form.
  696.  
  697. `set print object'
  698. `set print object on'
  699.      When displaying a pointer to an object, identify the *actual*
  700.      (derived) type of the object rather than the *declared* type,
  701.      using the virtual function table.
  702.  
  703. `set print object off'
  704.      Display only the declared type of objects, without reference to
  705.      the virtual function table.  This is the default setting.
  706.  
  707. `show print object'
  708.      Show whether actual, or declared, object types will be displayed.
  709.  
  710. `set print vtbl'
  711. `set print vtbl on'
  712.      Pretty print C++ virtual function tables.  The default is off.
  713.  
  714. `set print vtbl off'
  715.      Do not pretty print C++ virtual function tables.
  716.  
  717. `show print vtbl'
  718.      Show whether C++ virtual function tables are pretty printed, or
  719.      not.
  720.  
  721. 
  722. File: gdb.info,  Node: Value History,  Next: Convenience Vars,  Prev: Print Settings,  Up: Data
  723.  
  724. Value History
  725. =============
  726.  
  727.    Values printed by the `print' command are saved in GDB's "value
  728. history" so that you can refer to them in other expressions.  Values
  729. are kept until the symbol table is re-read or discarded (for example
  730. with the `file' or `symbol-file' commands).  When the symbol table
  731. changes, the value history is discarded, since the values may
  732. contain pointers back to the types defined in the symbol table.
  733.  
  734.    The values printed are given "history numbers" for you to refer to
  735. them by.  These are successive integers starting with one.  `print'
  736. shows you the history number assigned to a value by printing `$NUM =
  737. ' before the value; here NUM is the history number.
  738.  
  739.    To refer to any previous value, use `$' followed by the value's
  740. history number.  The way `print' labels its output is designed to
  741. remind
  742. you of this.  Just `$' refers to the most recent value in the
  743. history, and `$$' refers to the value before that.  `$$N' refers to
  744. the Nth value from the end; `$$2' is the value just prior to `$$',
  745. `$$1' is equivalent to `$$', and `$$0' is equivalent to `$'.
  746.  
  747.    For example, suppose you have just printed a pointer to a
  748. structure and want to see the contents of the structure.  It
  749. suffices to type
  750.  
  751.      p *$
  752.  
  753.    If you have a chain of structures where the component `next'
  754. points to the next one, you can print the contents of the next one
  755. with this:
  756.  
  757.      p *$.next
  758.  
  759. You can print successive links in the chain by repeating this
  760. command--which you can do by just typing RET.
  761.  
  762.    Note that the history records values, not expressions.  If the
  763. value of `x' is 4 and you type these commands:
  764.  
  765.      print x
  766.      set x=5
  767.  
  768. then the value recorded in the value history by the `print' command
  769. remains 4 even though the value of `x' has changed.
  770.  
  771. `show values'
  772.      Print the last ten values in the value history, with their item
  773.      numbers.  This is like `p $$9' repeated ten times, except that
  774.      `show values' does not change the history.
  775.  
  776. `show values N'
  777.      Print ten history values centered on history item number N.
  778.  
  779. `show values +'
  780.      Print ten history values just after the values last printed.  If
  781.      no more values are available, produces no display.
  782.  
  783.    Pressing RET to repeat `show values N' has exactly the same effect
  784. as `show values +'.
  785.  
  786. 
  787. File: gdb.info,  Node: Convenience Vars,  Next: Registers,  Prev: Value History,  Up: Data
  788.  
  789. Convenience Variables
  790. =====================
  791.  
  792.    GDB provides "convenience variables" that you can use within GDB
  793. to hold on to a value and refer to it later.  These variables exist
  794. entirely within GDB; they are not part of your program, and setting
  795. a convenience variable has no direct effect on further execution of
  796. your program.  That's why you can use them freely.
  797.  
  798.    Convenience variables are prefixed with `$'.  Any name preceded by
  799. `$' can be used for a convenience variable, unless it is one of the
  800. predefined machine-specific register names (*note Registers::.). 
  801. (Value history references, in contrast, are *numbers* preceded by
  802. `$'.  *Note Value History::.)
  803.  
  804.    You can save a value in a convenience variable with an assignment
  805. expression, just as you would set a variable in your program. 
  806. Example:
  807.  
  808.      set $foo = *object_ptr
  809.  
  810. would save in `$foo' the value contained in the object pointed to by
  811. `object_ptr'.
  812.  
  813.    Using a convenience variable for the first time creates it; but
  814. its value is `void' until you assign a new value.  You can alter the
  815. value with another assignment at any time.
  816.  
  817.    Convenience variables have no fixed types.  You can assign a
  818. convenience variable any type of value, including structures and
  819. arrays, even if that variable already has a value of a different
  820. type.  The convenience variable, when used as an expression, has the
  821. type of its current value.
  822.  
  823. `show convenience'
  824.      Print a list of convenience variables used so far, and their
  825.      values.  Abbreviated `show con'.
  826.  
  827.    One of the ways to use a convenience variable is as a counter to
  828. be incremented or a pointer to be advanced.  For example, to print a
  829. field from successive elements of an array of structures:
  830.  
  831.      set $i = 0
  832.      print bar[$i++]->contents
  833.      ... repeat that command by typing RET.
  834.  
  835.    Some convenience variables are created automatically by GDB and
  836. given values likely to be useful.
  837.  
  838. `$_'
  839.      The variable `$_' is automatically set by the `x' command to the
  840.      last address examined (*note Memory::.).  Other commands which
  841.      provide a default address for `x' to examine also set `$_' to
  842.      that address; these commands include `info line' and `info
  843.      breakpoint'.
  844.  
  845. `$__'
  846.      The variable `$__' is automatically set by the `x' command to
  847.      the value found in the last address examined.
  848.  
  849. 
  850. File: gdb.info,  Node: Registers,  Next: Floating Point Hardware,  Prev: Convenience Vars,  Up: Data
  851.  
  852. Registers
  853. =========
  854.  
  855.    Machine register contents can be referred to in expressions as
  856. variables with names starting with `$'.  The names of registers are
  857. different for each machine; use `info registers' to see the names
  858. used
  859. on your machine.
  860.  
  861. `info registers'
  862.      Print the names and values of all registers (in the selected
  863.      stack frame).
  864.  
  865. `info registers REGNAME'
  866.      Print the relativized value of register REGNAME.  REGNAME may be
  867.      any register name valid on the machine you are using, with or
  868.      without the initial `$'.
  869.  
  870.    The register names `$pc' and `$sp' are used on most machines for
  871. the program counter register and the stack pointer.  For example,
  872. you could print the program counter in hex with
  873.  
  874.      p/x $pc
  875.  
  876. or print the instruction to be executed next with
  877.  
  878.      x/i $pc
  879.  
  880. or add four to the stack pointer with
  881.  
  882.      set $sp += 4
  883.  
  884. The last is a way of removing one word from the stack, on machines
  885. where stacks grow downward in memory (most machines, nowadays). 
  886. This assumes that the innermost stack frame is selected; setting
  887. `$sp' is not allowed when other stack frames are selected.  (To pop
  888. entire frames off the stack, regardless of machine architecture, use
  889. `return'; *note Returning::..)
  890.  
  891.    Often `$fp' is used for a register that contains a pointer to the
  892. current stack frame, and `$ps' is sometimes used for a register that
  893. contains the processor status.  These standard register names may be
  894. available on your machine even though the `info registers' command
  895. shows other names.  For example, on the SPARC, `info registers'
  896. displays the processor status register as `$psr' but you can also
  897. refer
  898. to
  899. it as `$ps'.
  900.  
  901.    GDB always considers the contents of an ordinary register as an
  902. integer when the register is examined in this way.  Some machines
  903. have special registers which can hold nothing but floating point;
  904. these registers are considered to have floating point values.  There
  905. is no way to refer to the contents of an ordinary register as
  906. floating point value (although you can *print* it as a floating
  907. point value with `print/f $REGNAME').
  908.  
  909.    Some registers have distinct "raw" and "virtual" data formats. 
  910. This means that the data format in which the register contents are
  911. saved by the operating system is not the same one that your program
  912. normally sees.  For example, the registers of the 68881 floating
  913. point coprocessor are always saved in "extended" (raw) format, but
  914. all C programs expect to work with "double" (virtual) format.  In
  915. such cases, GDB normally works with the virtual format only (the
  916. format that makes sense for your program), but the `info registers'
  917. command prints the data in both formats.
  918.  
  919.    Normally, register values are relative to the selected stack frame
  920. (*note Selection::.).  This means that you get the value that the
  921. register would contain if all stack frames farther in were exited
  922. and their saved registers restored.  In order to see the true
  923. contents of hardware registers, you must select the innermost frame
  924. (with `frame 0').
  925.  
  926.    However, GDB must deduce where registers are saved, from the
  927. machine code generated by your compiler.  If some registers are not
  928. saved, or if GDB is unable to locate the saved registers, the
  929. selected stack frame will make no difference.
  930.  
  931. 
  932. File: gdb.info,  Node: Floating Point Hardware,  Prev: Registers,  Up: Data
  933.  
  934. Floating Point Hardware
  935. =======================
  936.  
  937.    Depending on the host machine architecture, GDB may be able to
  938. give you more information about the status of the floating point
  939. hardware.
  940.  
  941. `info float'
  942.      If available, provides hardware-dependent information about the
  943.      floating point unit.  The exact contents and layout vary
  944.      depending on the floating point chip.
  945.  
  946. 
  947. File: gdb.info,  Node: Symbols,  Next: Altering,  Prev: Data,  Up: Top
  948.  
  949. Examining the Symbol Table
  950. **************************
  951.  
  952.    The commands described in this section allow you to inquire about
  953. the symbols (names of variables, functions and types) defined in
  954. your program.  This information is inherent in the text of your
  955. program and does not change as the program executes.  GDB finds it
  956. in your program's symbol table, in the file indicated when you
  957. started GDB  (*note File Options::.), or by one of the
  958. file-management commands (*note Files::.).
  959.  
  960. `info address SYMBOL'
  961.      Describe where the data for SYMBOL is stored.  For a register
  962.      variable, this says which register it is kept in.  For a
  963.      non-register local variable, this prints the stack-frame offset
  964.      at which the variable is always stored.
  965.  
  966.      Note the contrast with `print &SYMBOL', which does not work at
  967.      all for a register variables, and for a stack local variable
  968.      prints the exact address of the current instantiation of the
  969.      variable.
  970.  
  971. `whatis EXP'
  972.      Print the data type of expression EXP.  EXP is not actually
  973.      evaluated, and any side-effecting operations (such as
  974.      assignments or function calls) inside it do not take place. 
  975.     
  976.      *Note Expressions::.
  977.  
  978. `whatis'
  979.      Print the data type of `$', the last value in the value history.
  980.  
  981. `ptype TYPENAME'
  982.      Print a description of data type TYPENAME.  TYPENAME may be the
  983.      name of a type, or for C code it may have the form `struct
  984.      STRUCT-TAG', `union UNION-TAG' or `enum ENUM-TAG'.
  985.  
  986. `ptype EXP'
  987.      Print a description of the type of expression EXP.  `ptype'
  988.      differs from `whatis' by printing a detailed description,
  989.      instead of just the name of the type.  For example, if your
  990.      program declares a variable as
  991.  
  992.           struct complex {double real; double imag;} v;
  993.  
  994.      compare the output of the two commands:
  995.  
  996.           (gdb) whatis v
  997.           type = struct complex
  998.           (gdb) ptype v
  999.           type = struct complex {
  1000.               double real;
  1001.               double imag;
  1002.           }
  1003.  
  1004. `info types REGEXP'
  1005. `info types'
  1006.      Print a brief description of all types whose name matches REGEXP
  1007.      (or all types in your program, if you supply no argument). 
  1008.      Each complete typename is matched as though it were a complete
  1009.      line; thus, `i type value' gives information on all types in
  1010.      your program whose name includes the string `value', but `i
  1011.      type ^value$' gives information only on types whose complete
  1012.      name is `value'.
  1013.  
  1014.      This command differs from `ptype' in two ways: first, like
  1015.      `whatis', it does not print a detailed description; second, it
  1016.      lists all source files where a type is defined.
  1017.  
  1018. `info source'
  1019.      Show the name of the current source file--that is, the source
  1020.      file for the function containing the current point of execution.
  1021.  
  1022. `info sources'
  1023.      Print the names of all source files in the program for which
  1024.      there is debugging information, organized into two lists: those
  1025.      for which symbols have been read in, and those for which
  1026.      symbols will be read in on demand.
  1027.  
  1028. `info functions'
  1029.      Print the names and data types of all defined functions.
  1030.  
  1031. `info functions REGEXP'
  1032.      Print the names and data types of all defined functions whose
  1033.      names contain a match for regular expression REGEXP.  Thus,
  1034.      `info fun step' finds all functions whose names include `step';
  1035.      `info fun ^step' finds those whose names start with `step'.
  1036.  
  1037. `info variables'
  1038.      Print the names and data types of all variables that are
  1039.      declared outside of functions (i.e., excluding local variables).
  1040.  
  1041. `info variables REGEXP'
  1042.      Print the names and data types of all variables (except for
  1043.      local variables) whose names contain a match for regular
  1044.      expression REGEXP.
  1045.  
  1046. `printsyms FILENAME'
  1047.      Write a complete dump of the debugger's symbol data into the
  1048.      file FILENAME.
  1049.  
  1050. 
  1051. File: gdb.info,  Node: Altering,  Next: GDB Files,  Prev: Symbols,  Up: Top
  1052.  
  1053. Altering Execution
  1054. ******************
  1055.  
  1056.    Once you think you have found an error in the program, you might
  1057. want to find out for certain whether correcting the apparent error
  1058. would lead to correct results in the rest of the run.  You can find
  1059. the answer by experiment, using the GDB features for altering
  1060. execution of the program.
  1061.  
  1062.    For example, you can store new values into variables or memory
  1063. locations, give the program a signal, restart it at a different
  1064. address, or even return prematurely from a function to its caller.
  1065.  
  1066. * Menu:
  1067.  
  1068. * Assignment::            Assignment to Variables
  1069. * Jumping::            Continuing at a Different Address
  1070. * Signaling::            Giving the Program a Signal
  1071. * Returning::            Returning from a Function
  1072. * Calling::            Calling your Program's Functions
  1073.  
  1074. 
  1075. File: gdb.info,  Node: Assignment,  Next: Jumping,  Prev: Altering,  Up: Altering
  1076.  
  1077. Assignment to Variables
  1078. =======================
  1079.  
  1080.    To alter the value of a variable, evaluate an assignment expression.
  1081. *Note Expressions::.  For example,
  1082.  
  1083.      print x=4
  1084.  
  1085. would store the value 4 into the variable `x', and then print the
  1086. value
  1087. of the assignment expression (which is 4).  All the assignment
  1088. operators of C are supported, including the increment operators `++'
  1089. and `--', and combining assignments such as `+=' and `<<='.
  1090.  
  1091.    If you are not interested in seeing the value of the assignment,
  1092. use
  1093. the `set' command instead of the `print' command.  `set' is really
  1094. the same as `print' except that the expression's value is not
  1095. printed and is not put in the value history (*note Value
  1096. History::.).  The expression is evaluated only for its effects.
  1097.  
  1098.    If the beginning of the argument string of the `set' command
  1099. appears
  1100. identical to a `set' subcommand, use the `set variable' command
  1101. instead of just `set'.  This command is identical to `set' except
  1102. for its lack of subcommands.  For example, a program might well have
  1103. a variable `width'--which leads to an error if we try to set a new
  1104. value with just `set width=13', as we might if `set width' didn't
  1105. happen to be a GDB command:
  1106.  
  1107.      (gdb) whatis width
  1108.      type = double
  1109.      (gdb) p width
  1110.      $4 = 13
  1111.      (gdb) set width=47
  1112.      Invalid syntax in expression.
  1113.  
  1114. The invalid expression, of course, is `=47'.  What we can do in order
  1115. to actually set our program's variable `width' is
  1116.  
  1117.      (gdb) set var width=47
  1118.  
  1119.    GDB allows more implicit conversions in assignments than C does;
  1120. you can freely store an integer value into a pointer variable or
  1121. vice
  1122. versa, and any structure can be converted to any other structure
  1123. that is the same length or shorter.
  1124.  
  1125.    To store values into arbitrary places in memory, use the `{...}'
  1126. construct to generate a value of specified type at a specified
  1127. address (*note Expressions::.).  For example, `{int}0x83040' refers
  1128. to memory location `0x83040' as an integer (which implies a certain
  1129. size and representation in memory), and
  1130.  
  1131.      set {int}0x83040 = 4
  1132.  
  1133. stores the value 4 into that memory location.
  1134.  
  1135. 
  1136. File: gdb.info,  Node: Jumping,  Next: Signaling,  Prev: Assignment,  Up: Altering
  1137.  
  1138. Continuing at a Different Address
  1139. =================================
  1140.  
  1141.    Ordinarily, when you continue the program, you do so at the place
  1142. where it stopped, with the `continue' command.  You can instead
  1143. continue at an address of your own choosing, with the following
  1144. commands:
  1145.  
  1146. `jump LINESPEC'
  1147.      Resume execution at line LINESPEC.  Execution will stop
  1148.      immediately if there is a breakpoint there.  *Note List:: for a
  1149.      description of the different forms of LINESPEC.
  1150.  
  1151.      The `jump' command does not change the current stack frame, or
  1152.      the stack pointer, or the contents of any memory location or
  1153.      any register other than the program counter.  If line LINESPEC
  1154.      is in a different function from the one currently executing,
  1155.      the results may be bizarre if the two functions expect
  1156.      different patterns of arguments or of local variables.  For
  1157.      this
  1158.      reason, the `jump' command requests confirmation if the
  1159.      specified line is not in the function currently executing. 
  1160.      However, even bizarre results are predictable if you are well
  1161.      acquainted with the machine-language code of the program.
  1162.  
  1163. `jump *ADDRESS'
  1164.      Resume execution at the instruction at address ADDRESS.
  1165.  
  1166.    You can get much the same effect as the `jump' command by storing
  1167. a new value into the register `$pc'.  The difference is that this
  1168. does not start the program running; it only changes the address
  1169. where it *will* run when it is continued.  For example,
  1170.  
  1171.      set $pc = 0x485
  1172.  
  1173. causes the next `continue' command or stepping command to execute at
  1174. address 0x485, rather than at the address where the program stopped.
  1175. *Note Continuing and Stepping::.
  1176.  
  1177.    The most common occasion to use the `jump' command is to back up,
  1178. perhaps with more breakpoints set, over a portion of a program that
  1179. has already executed, in order to examine its execution in more
  1180. detail.
  1181.  
  1182. 
  1183. File: gdb.info,  Node: Signaling,  Next: Returning,  Prev: Jumping,  Up: Altering
  1184.  
  1185. Giving the Program a Signal
  1186. ===========================
  1187.  
  1188. `signal SIGNALNUM'
  1189.      Resume execution where the program stopped, but give it
  1190.      immediately the signal number SIGNALNUM.
  1191.  
  1192.      Alternatively, if SIGNALNUM is zero, continue execution without
  1193.      giving a signal.  This is useful when the program stopped on
  1194.      account of a signal and would ordinary see the signal when
  1195.      resumed with the `continue' command; `signal 0' causes it to
  1196.      resume without a signal.
  1197.  
  1198.      `signal' does not repeat when you press RET a second time after
  1199.      executing the command.
  1200.  
  1201. 
  1202. File: gdb.info,  Node: Returning,  Next: Calling,  Prev: Signaling,  Up: Altering
  1203.  
  1204. Returning from a Function
  1205. =========================
  1206.  
  1207. `return'
  1208. `return EXPRESSION'
  1209.      You can cancel execution of a function call with the `return'
  1210.      command.  If you give an EXPRESSION argument, its value is used
  1211.      as the function's return value.
  1212.  
  1213.    When you use `return', GDB discards the selected stack frame (and
  1214. all frames within it).  You can think of this as making the
  1215. discarded frame return prematurely.  If you wish to specify a value
  1216. to be returned, give that value as the argument to `return'.
  1217.  
  1218.    This pops the selected stack frame (*note Selection::.), and any
  1219. other frames inside of it, leaving its caller as the innermost
  1220. remaining frame.  That frame becomes selected.  The specified value
  1221. is stored in the registers used for returning values of functions.
  1222.  
  1223.    The `return' command does not resume execution; it leaves the
  1224. program stopped in the state that would exist if the function had
  1225. just returned.  In contrast, the `finish' command (*note Continuing
  1226. and Stepping::.) resumes execution until the selected stack frame
  1227. returns naturally.
  1228.  
  1229. 
  1230. File: gdb.info,  Node: Calling,  Prev: Returning,  Up: Altering
  1231.  
  1232. Calling your Program's Functions
  1233. ================================
  1234.  
  1235. `call EXPR'
  1236.      Evaluate the expression EXPR without displaying `void' returned
  1237.      values.
  1238.  
  1239.    You can use this variant of the `print' command if you want to
  1240. execute a function from your program, but without cluttering the
  1241. output with `void' returned values.  The result is printed and saved
  1242. in the value history, if it is not void.
  1243.  
  1244. 
  1245. File: gdb.info,  Node: GDB Files,  Next: Targets,  Prev: Altering,  Up: Top
  1246.  
  1247. GDB's Files
  1248. ***********
  1249.  
  1250. * Menu:
  1251.  
  1252. * Files::            Commands to Specify Files
  1253. * Symbol Errors::        Errors Reading Symbol Files
  1254.  
  1255.